GoodTools = {
    /**
     * @description 按照商品号删除
     * @param gid
     */

    deleteGoodByID: function (gid, size) {
        //考虑2种情况,商品存放在购物车里和cookie里
        if (JSON.parse(sessionStorage.getItem("userInfo"))) {
            let User = JSON.parse(sessionStorage.getItem("userInfo"));
            let obj = {
                "uid": User.id,
                "gid": gid,
                "size": size
            }
            console.log(obj);
            $.ajax({
                url: "../../server/cart/deleteGoodByGid.php",
                data: obj,
                type: "post"
            }).then(function (res) {
                console.log(res);
            })
        } else {
            //未登录
            if ($.cookie("carts")) {
                let cookieList = JSON.parse($.cookie("carts"));
                cookieList.some((ele, index) => {
                    if (ele.gid == gid && ele.size == size) {
                        cookieList.splice(index, 1);
                        console.log(cookieList);
                        $.cookie("carts", JSON.stringify(cookieList));
                    }
                })
            }
        }
    },
    /**
     * @description 改变购买的某件商品的数量
     * @param gid
     * @param num
     */
    updateGoodByName: function (gid, num, price, size) {
        //如果登录了
        if (JSON.parse(sessionStorage.getItem("userInfo"))) {
            let User = JSON.parse(sessionStorage.getItem("userInfo"));
            let obj = {
                "uid": User.id,
                "gid": gid,
                "num": num,
                "price": price
            }
            $.ajax({
                url: "../../server/product/updateNumByGood.php",
                data: obj,
                type: "post"
            }).then(function (res) {

            })
        } else {
            //未登录
            if ($.cookie("carts")) {
                let cookieList = JSON.parse($.cookie("carts"));
                let flag = cookieList.some((ele, index) => {
                    if (ele.gid == gid && ele.size == size) {
                        cookieList[index].num = num;
                        cookieList[index].totalprice = cookieList[index].price * num;
                        $.cookie("carts", JSON.stringify(cookieList));

                    }
                })
            }
        }
    }

}